Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Top 150 Core Java Online Practice Test | Multiple Choice

Top 150 Core Java Online Practice Test | Multiple Choice
1. Java is case _
  Sensitive
  Insensitive
2. What a Java programmer calls a __ , a C/C++ programmer calls a function?
  Method
  Object
3. enum is a Keyword in Java, introduced from J2SE 5
  TRUE
  FALSE
4. The Separator [ ] is Used to declare array types
  TRUE
  FALSE
5. Can there be an abstract class with no abstract methods in it?
  Yes
  No
6. Can an Interface have an inner class?
  Yes
  No
7. Which of the following would compile without error?
  int a = Math.abs(-5);
  int b = Math.abs(5.0);
  int c = Math.abs(5.5F);
  int d = Math.abs(5L);
8. Which of the following are valid calls to Math.max?

Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
  1, 2 and 4
  2, 3 and 4
  1, 2 and 3
  2, 3 and 4
9. Which interface does java.util.HashTable implement?
  Java.util.Map
  Java.util.List
  Java.util.HashTable
  Java.util.Collection
10. Which interface provides the capability to store objects using a key-value pair?
  Java.util.Map
  Java.util.Set
  Java.util.List
  Java.util.Collection
11. Which is valid declaration of a float?
  float f = 1F;
  float f = 1.0;
  float f = "1";
  float f = 1.0d;
12. Which of the following are Java reserved words?

1) run
2) import
3) default
4) implement
  2 and 3
  2 and 4
  3 and 4
  1 and 2
13. Which of the following will directly stop the execution of a Thread?
  wait()
  notify()
  notifyall()
  exits synchronized code
14. Which will contain the body of the thread?
  run();
  stop();
  start();
  main();
15. Assume the following method is properly synchronized and called from a thread A on an object B:

wait(2000);

After calling this method, when will the thread A become a candidate to get another turn at the CPU?
  After thread A is notified, or after two seconds.
  After the lock on B is released, or after two seconds.
  Two seconds after lock B is released.
  Two seconds after thread A is notified.
16. Which of the following will not directly cause a thread to stop?
  notify()
  wait()
  sleep()
  InputStream access
17. Which class or interface defines the wait(), notify(),and notifyAll() methods?
  Object
  Runnable
  Class
  Thread
18. Which is a valid keyword in java?
  interface
  Float
  string
  unsigned
19. Which is the valid declarations within an interface definition?
  public double method();
  public final double method();
  static void method(double d1);
  protected void method(double d1);
20. Which is a valid declarations of a String?
  String s = null;
  String s = 'null';
  String s = (String) 'ufeed';
  String s = (String) 'abc';
21. Given:
class Super {
public float getNum( ) {
return 3.0f;
}
}

public class Sub extends Super {
}

Which method, placed after 'public class Sub extends Super {', causes compilation to fail?
  public void getNum( ) { }
  public void getNum(double d) { }
  public float getNum( ) { return 4.0f; }
  public double getNum(float d) { return 4.0d; }
22. Which one allow the class Thing to be instantiated using new Thing( )?
  public class Thing { }
  public class Thing { public Thing(void) {} }
  public class Thing { public Thing(String s) {} }
23. Given:
public class ArrayTest {
public static void main(String[ ] args){
float f1[ ]=f[ ];
f1 = new float[10];
f = f1;
System.out.println("f[0] = " + f[0]);
}
}

What is the result?
  It prints f2[0] = 0.0
  It prints f2[0] = NaN
  An error at 'f2 = f1;' causes compile to fail.
  An error at 'System.out.println("f2[0] = " + f2[0]);' causes compile to fail.
24. Which one cause a compiler error?
  float[ ] f = new float(3);
  float f3[ ] = new float[3];
  float[ ]f1 = new float[3];
25. After the following code fragment, what is the value in a?

String s;
int a;
s = "Foolish boy.";
a = s.indexOf("fool");
  -1
  0
  4
  random value
26. Given the following statement:
wb.setDouble(8.0*32.2+1.0);
What must be the data type of wb?
  DoubleField
  TextField
  IntField
  double
27. A compound statement is:
  A collection of one or more statements enclosed in
braces
  A statement involving if and else
  A way of declaring variables
  a way of setting the value of a variable
28. The data type for numbers such as 3.14159 is:
  double
  int
  real
  String
29. A function is:
  An entity that receives inputs and outputs
  A way of storing values
  A sequence of characters enclosed by quotes
  A kind of computer
30. What will be the output of the program?

public class WBFoo
{
public static void main(String[] args)
{
try
{
return;
}
finally
{
System.out.println( "Finally" );
}
}
}
  Finally
  Compilation fails
  An exception is thrown at runtime
  The code runs with no output
31. What will be the output of the program?

try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
  Compilation fails
  finished
  Exception
  Arithmetic Exception
32. What will be the output of the program?

public class WithoutBook
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod() {}
}
  ACD
  AB
  AC
  BC
33. Which two of the following methods are defined in class Thread?

1. start()
2. wait()
3. notify()
4. run()
5. terminate()
  1 and 4
  3 and 4
  2 and 3
  2 and 4
34. Which of the following will directly stop the execution of a Thread?
  wait()
  notify()
  notifyall()
  exits synchronized code
35. Which of the following will not directly cause a thread to stop?
  notify()
  wait()
  sleep()
  InputStream access
36. Which class or interface defines the wait(), notify(),and notifyAll() methods?
  Object
  Runnable
  Thread
  Class
37. public Object wb()
{
Object o = new Float(3.14F);
Object [] oa = new Object[l];
oa[0] = o; /* Line 5 */
o = null; /* Line 6 */
oa[0] = null; /* Line 7 */
return o; /* Line 8 */
}
When is the Float object, created in line 3, eligible for garbage collection?
  just after line 7
  just after line 5
  just after line 6
  just after line 8
38. Which of the following would compile without error?
  int a = Math.abs(-5);
  int b = Math.abs(5.0);
  int d = Math.abs(5L);
  int c = Math.abs(5.5F);
39. What will be the output of the program?

int i = 1, j = 10;
do
{
if(i++ > --j)
{
continue;
}
} while (i < 5);
System.out.println("i = " + i + "and j = " + j);
  i = 5 and j = 6
  i = 6 and j = 5
  i = 5 and j = 5
  i = 6 and j = 6
40. What will be the output of the program?

System.out.println(Math.sqrt(-4D));
  NaN
  -2
  Compile Error
  Runtime Exception
41. What will be the output of the program?

class Tree { }
class Pine extends Tree { }
class Oak extends Tree { }
public class Forest1
{
public static void main (String [] args)
{
Tree tree = new Pine();
if( tree instanceof Pine )
System.out.println ("Pine");
else if( tree instanceof Tree )
System.out.println ("Tree");
else if( tree instanceof Oak )
System.out.println ( "Oak" );
else
System.out.println ("Oops ");
}
}
  Pine
  Tree
  Forest
  Oops
42. The Java interpreter is used for the execution of the source code.
  True
  False
43. On successful compilation a file with the class extension is created.
  True
  False
44. The Java source code can be created in a Notepad editor.
  True
  False
45. The Java Program is enclosed in a class definition.
  True
  False
46. Java supports multidimensional arrays.
  True
  False
47. An array of arrays can be created.
  True
  False
48. When a string literal is used in the program, Java automatically creates instances of the string class.
  True
  False
49. Which of the following are primitive types?
  byte
  String
  Integer
  Float
50. public class CoreJavaOnlineTest1 {
public static void main(String[] args) {
String s1 = "withoutbook";
String s2 = s1;
s1 = null;
System.out.println("s1:"+s1+" s2:"+s2);
}
}

What is the output?
  s1:null s2:withoutbook
  s1:null s2:null
  Exception
  None of the above
51. Palindrome nos are which from the below:
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33
  0, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21
  0, 5, 10, 15, 20, 25
  0, 1, 1, 2, 3, 5, 8, 13, 21
52. package testpackage;

class Test {
public static void main (String[] args){
try{
System.out.println("I am withoutbook.");
}catch(Exception e){
e.printStackTrace();
}catch(NullPointerException e){
e.printStackTrace();
}
}
}

What is the output?
  Exception as java.lang.NullPointerException has already been caught
  Compile time exception
  Runtime exception
  I am withoutbook.
53. Switch statement can hold which type from options:
  int, short, char, enum
  int, short, long
  int, short, char, long
  int, char, boolean
54. Which are correct input-output options :

public class Test{
public static void main(String args[])
{
public int test(char a) {
if (a <= 'N') {
if (a == 'E')
return 2;
return 1;
} else if (a == 'S')
return 3;
else if (a == 'W')
return 4;
return 0; }
}
}
  a='X' output=0
  a='D' output=0
  Compile error.
  None of the above.
55. interface Test{
void f1(); // 1
public void f2(); // 2
protected void f3(); // 3
private void f4(); // 4
}

which lines generate compile time errors?
  compiletime error at lines 3,4
  compiletime error at line 1
  compiletime error at line 3
  compiletime error at lines 1,2,3,4
56. class Test
{
static class C
{
static int i1;
}
public static void main(String a[])
{
System.out.println(Test.C.i1);
}
}

What is the result of attempting to compile and run the program?
  prints 0
  Compile time error
  Runtime exception
  None of the above
57. Each element must be unique
Duplicate elements must not replace old elements.
Elements are not key/value pairs.
Accessing an element can be almost as fast as performing a similar operation on an array.

Which of these classes provide the specified features?
  HashSet
  HashMap
  TreeMap
  LinkedList
58. class Test1
{
static interface I
{
static class Test2
{
}
}
public static void main(String a[])
{
Test1.I.Test2 ob1=new Test1.I.Test2();
System.out.println("object created");
}
}

What is the result of attempting to compile and run the program?
  prints object created
  Runtime Exception
  Compile time error
  None of the above
59. What is byte code in the context of Java?
  The type of code generated by a Java compiler.
  The type of code generated by a Java Virtual Machine.
  It is another name for a Java source file.
  It is the code written within the instance methods of a class.
60. What is the output of the following code:
package testpackage;

public class Test{
public static void main(String args[]){
int sum = 0, p = 1;
for (int count = 1; count <= 50; count++)
{
sum += p;
p *= 2;
}
System.out.println(sum);
}
}
  -1
  1125899906842623
  ArithmeticException
  IllegalArgumentException
61. What gets printed when the following code is compiled and run with the following command -
java test 2
Select the one correct answer.

public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();

if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
  1
  0
  test -1
  test
62. Is the following statement true or false. The constructor of a class must not have a return type.
  TRUE
  FALSE
63. Which of the following is true. Select the correct answer.
  A class that is abstract may not be instantiated.
  The final keyword indicates that the body of a method is to be found elsewhere. The code is written in non-Java language, typically in C/C++.
  A method defined as private indicates that it is accessible to all other classes in the same package.
  A static variable indicates there are multiple copies of that variable.
64. What all gets printed when the following gets compiled and run. Select the correct answer.

public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i/j > 1)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
  0
3
4
  0
1
2
  0
2
3
  1
2
3
65. What all gets printed when the following gets compiled and run. Select the correct answer.

public class test {
public static void main(String args[]) {
int i=1, j=1;
try {
i++;
j--;
if(i == j)
i++;
}
catch(ArithmeticException e) {
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println(1);
}
catch(Exception e) {
System.out.println(2);
}
finally {
System.out.println(3);
}
System.out.println(4);
}
}
  3
4
  0
1
  1
2
  2
3
66. What all gets printed when the following gets compiled and run. Select the correct answer.

public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
  1
3
  1
2
  2
3
  3
1
67. What gets printed when the following code is compiled and run. Select the one correct answer.

public class test {
public static void main(String args[]) {
int i = 1;
do {
i--;
} while (i > 2);
System.out.println(i);
}
}
  0
  1
  2
  -1
68. Which of these is a legal definition of a method named m assuming it throws IOException, and returns void. Also assume that the method does not take any arguments. Select the one correct answer.
  void m() throws IOException{}
  void m() throw IOException{}
  void m() {} throws IOException
  m() throws IOException{}
69. If a base class has a method defined as
void method() { }
Which of the following are legal prototypes in a derived class of this class. Select the correct answer.
  void method() { }
  int method() { return 0;}
  private void method() { }
70. Is the following statement true or false. As the toString method is defined in the Object class, System.out.println can be used to print any object.
  True
  False
71. What is the result of compiling and running the following program.

public class test {
public static void main(String args[]) {
String str1="abc";
String str2="def";
String str3=str1.concat(str2);

str1.concat(str2);
System.out.println(str1);
}
}
  abc
  def
  abcabc
  abcdef
72. What is the process by which one object acquires the properties of another object?
  Polymorphism
  Inheritence
73. What is a highly optimized set of instructions designed to be executed by the Java run-time system?
  View Code
  Byte Code
74. What does J2SE mean?
  Java 2 Platform Independent Standard Edition
  Java 2 Platform Standard Edition
75. Java does not supports multithreaded programming.
  TRUE
  FALSE
76. The Separator, Comma is Used to separate package names from subpackages and classes
  TRUE
  FALSE
77. Objects are sometimes referred to as __ of a class
  Interface
  Instance
78. When Java source code is compiled, each individual class is put into its own output file named after the class and using the __ extension
  .java
  .class
79. Can an Interface be final?
  Yes
  No
80. Can we define private and protected modifiers for variables in interfaces?
  Yes
  No
81. Can a Byte object be cast to a double value?
  Yes
  No
82. A class can be converted to a thread by implementing the interface __
  Thread
  Runnable
83. What is the output of following piece of code ?
int x = 2;
switch (x) {
case 1:System.out.println("1″);
case 2:
case 3:System.out.println("3″);
case 4:
case 5:System.out.println("5″);
}
  1, 3 and 5
  3 and 5
84. What will be the result of attempting to compile and run this.

class Base{}
class Derived extends Base{}
public class Test {
public static void main(String[] args){
Derived d = (Derived) new Base();
}
}
  Compiles and runs without error.
  Runtime error
85. What is the value of "d" after this line of code has been executed?

double d = Math.round ( 2.5 + Math.random( ));
  2
  3
  4
  4.5
86. You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provides that capability?
  java.util.Map
  java.util.Set
  java.util.List
  java.util.Collection
87. Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO (first-in, first-out) sequence?
  java.util.ArrayList
  java.util.LinkedHashMap
  java.util.HashMap
  java.util.TreeMap
88. What is the name of the method used to start a thread execution?
  init();
  start();
  run();
  resume();
89. Which method registers a thread in a thread scheduler?
  run();
  start();
  construct();
  register();
90. Which one of these lists contains only Java programming language keywords?
  class, if, void, long, Int, continue
  goto, instanceof, native, finally, default, throws
  try, virtual, throw, final, volatile, transient
  strictfp, constant, super, implements, do
91. Which is true about a method-local inner class?
  It must be marked final.
  It can be marked abstract.
  It can be marked static.
  It can be marked public.
92. Which statement is true about a static nested class?
  You must have a reference to an instance of the enclosing class in order to instantiate it.
  It does not have access to nonstatic members of the enclosing class.
  It must extend the enclosing class.
  It's variables and methods must be static.
93. Given
class Base{
Base(){
System.out.print("Base");
}
}

public class Alpha extends Base{
public static void main(String[] args){
new Alpha();
new Base();
}
}

What is the result?
  Base
  BaseBase
  Compilation fails
  The code runs with no output
94. Given:
class A {
A( ) {
}
}
class B extends A {
}

Which statement is true?
  Class B'S constructor is public.
  Class B'S constructor has no arguments.
  Class B'S constructor includes a call to this( ).
95. Which cause a compiler error?
  int[ ] scores = {3, 5, 7};
  int [ ][ ] scores = {2,7,6}, {9,3,45};
  String cats[ ] = {"Fluffy", "Spot", "Zeus"};
96. You want to limit access to a method of a public class to members of the same class. Which access accomplishes this objective?
  public
  private
  protected
  transient
97. What is an infinite loop?
  A loop that functions infinitely well
  A loop that runs forever
  A loop that never starts
  A loop that will never function
98. What is the purpose of this bit of code

void init()
{
...
}
  a class that initializes the applet
  A required method in an applet
  A place to declare variables
  Interacting with the user
99. The following is NOT an example of a data type.
  int
  public
  void
  double
100. What is the value stored in result after executing the following line in a program?

result = 6/2*3;
  1.2
  9
  1
  0
101. What will be the output of the program?

public class WithoutBook
{
public static void main(String args[])
{
try
{
System.out.print("Hello world ");
}
finally
{
System.out.println("Finally executing ");
}
}
}
  Hello world.
  Hello world Finally executing
  Nothing. The program will not compile because no catch clauses are specified.
  Nothing. The program will not compile because no exceptions are specified.
102. What is the name of the method used to start a thread execution?
  init()
  start()
  run()
  resume()
103. Which two are valid constructors for Thread?

1. Thread(Runnable r, String name)
2. Thread()
3. Thread(int priority)
4. Thread(Runnable r, ThreadGroup g)
5. Thread(Runnable r, int priority)
  2 and 5
  1 and 2
  2 and 4
  1 and 3
104. Which three are methods of the Object class?

1. notify();
2. notifyAll();
3. isInterrupted();
4. synchronized();
5. interrupt();
6. wait(long msecs);
7. sleep(long msecs);
8. yield();
  2,3,4
  1,2,6
  2,4,5
  1,2,4
105. Which three guarantee that a thread will leave the running state?

1. yield()
2. wait()
3. notify()
4. notifyAll()
5. sleep(1000)
6. aLiveThread.join()
7. Thread.killThread()
  4, 5 and 7
  2, 5 and 6
  3, 4 and 7
  1, 2 and 4
106. Which method registers a thread in a thread scheduler?
  run()
  start()
  construct()
  register()
107. public class MyRunnable implements Runnable
{
public void run()
{
// some code here
}
}
which of these will create and start this thread?
  new MyRunnable().start();
  new Thread(new MyRunnable()).start();
  new Thread(MyRunnable).run();
  new Runnable(MyRunnable).start();
108. class WithoutBook
{
private Demo d;
void start()
{
d = new Demo();
this.takeDemo(d); /* Line 7 */
} /* Line 8 */
void takeDemo(Demo demo)
{
demo = null;
demo = new Demo();
}
}
When is the Demo object eligible for garbage collection?
  After the start() method completes
  When the instance running this code is made eligible for garbage collection.
  After line 7
  After line 8
109. public class WithoutBook
{
public static void main(String [] args)
{
WithoutBook x = new WithoutBook();
WithoutBook x2 = m1(x); /* Line 6 */
WithoutBook x4 = new WithoutBook();
x2 = x4; /* Line 8 */
doComplexStuff();
}
static WithoutBook m1(WithoutBook mx)
{
mx = new WithoutBook();
return mx;
}
}
After line 8 runs. how many objects are eligible for garbage collection?
  0
  1
  2
  3
110. What allows the programmer to destroy an object x?
  Runtime.getRuntime().gc()
  Only the garbage collection system can destroy an object.
  x.finalize()
  x.delete()
111. What is the value of "d" after this line of code has been executed?

double d = Math.round ( 2.5 + Math.random( ));
  2
  3
  4
  2.5
112. Which of the following are valid calls to Math.max?

Math.max(1,4)
Math.max(2.3, 5)
Math.max(1, 3, 5, 7)
Math.max(-1.5, -2.8f)
  1, 2 and 3
  1, 2 and 4
  2, 3 and 4
  2, 3 and 4
113. What will be the output of the program?

int i = (int) Math.random();
  i = 1
  i = 0
  Statement causes a compile error
  value of i is undetermined
114. What will be the output of the program?

class A
{
public A(int x){}
}
class B extends A { }
public class test
{
public static void main (String args [])
{
A a = new B();
System.out.println("complete");
}
}
  Prints "complete"
  Compile Error
  It compiles and runs printing nothing
  Compiles but fails at runtime
115. What will be the output of the program?

public class StringRef
{
public static void main(String [] args)
{
String s1 = "abc";
String s2 = "def";
String s3 = s2;
s2 = "ghi";
System.out.println(s1 + s2 + s3);
}
}
  abcghighi
  abcghidef
  abcdefdef
  abcdefghi
116. What will be the output of the program?

public class WithoutBook
{
public static void stringReplace (String text)
{
text = text.replace ('j' , 'c');
}
public static void bufferReplace (StringBuffer text)
{
text = text.append ("c");
}
public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer ("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
}
}
  java
  javajavac
  Compile error
  javac
117. What will be the output of the program?

String s = "hello";
Object o = s;
if( o.equals(s) )
{
System.out.println("A");
}
else
{
System.out.println("B");
}
if( s.equals(o) )
{
System.out.println("C");
}
else
{
System.out.println("D");
}

1. A
2. B
3. C
4. D
  2 and 4
  1 and 3
  3 and 4
  1 and 2
118. What will be the output of the program?

public class BoolTest
{
public static void main(String [] args)
{
Boolean b1 = new Boolean("false");
boolean b2;
b2 = b1.booleanValue();
if (!b2)
{
b2 = true;
System.out.print("x ");
}
if (b1 & b2)
{
System.out.print("y ");
}
System.out.println("z");
}
}
  z
  x z
  y z
  Compilation fails.
119. Converting of primitive types to objects can be explicitly.
  True
  False
120. public class CoreJavaOnlineTest1 {
public void main(String[] args) {
System.out.println("WithoutBook Test Example.");
}
}

What is the output?
  WithoutBook Test Example.
  java.lang.NoSuchMethodError
  No output
  No Exception
121. public class CoreJavaOnlineTest1 {
public static void main(String[] args) {
String s = "raidua";
System.out.println(s.lastIndexOf('a', 2));
}
}

What is the output?
  -1
  1
  2
  5
122. A signed data type has an equal number of non-zero positive and negative values available.
  True
  False
123. Suppose Class B extends Class A.
And all classes extends Object.

So here Class B extending Class A and Object both. So is it multiple inheritance?
  True
  False
124. What all gets printed when the following code is compiled and run? Select the three correct answers.

public class xyz {
public static void main(String args[]) {
for(int i = 0; i < 2; i++) {
for(int j = 2; j>= 0; j--) {
if(i == j) break;
System.out.println("i=" + i + " j="+j);
}
}
}
}
  i=0 j=0
i=0 j=1
i=0 j=2
  i=0 j=1
i=0 j=2
i=1 j=2
  i=2 j=0
i=2 j=1
i=2 j=2
  i=1 j=0
i=1 j=1
i=1 j=2
125. What is the result of evaluating the expression 14 ^ 23. Select the one correct answer.
  37
  25
  6
  31
126. Which of the following are true. Select the one correct answer.
  ~ operator is the bit-wise XOR operator.
  && operator is used for short-circuited logical AND.
  | operator is used to perform bitwise OR and also short-circuited logical OR.
  The unsigned right shift operator in Java is >>.
127. What all gets printed when the following gets compiled and run. Select the correct answer.

public class test {
public static void main(String args[]) {
String s1 = "abc";
String s2 = new String("abc");

if(s1 == s2)
System.out.println(1);
else
System.out.println(2);
if(s1.equals(s2))
System.out.println(3);
else
System.out.println(4);
}
}
  1
2
  2
3
  1
3
  2
1
128. String s = new String("xyz");
Assuming the above declaration, which of the following statements would compile. Select the one correct answer.
  s = s >> 2;
  s = s + s;
  int i = s[0];
  s = 2 * s;
129. In which all cases does an exception gets generated. Select the two correct answers.

int i = 0, j = 1;
  if((i == 0) || (j/i == 1))
  if((i == 0) | (j/i == 1))
  if((i != 0) && (j/i == 1))
  None of the above
130. Which of the following statements are true. Select the correct answer.
  The wait method defined in the Thread class, can be used to convert a thread from Running state to Waiting state.
  The wait(), notify(), and notifyAll() methods must be executed in synchronized code.
  The Thread class is an abstract class.
  The notify() and notifyAll() methods can not be used to signal and move waiting threads to ready-to-run state.
131. Which of these classes implement the Collection interface SortedMap. Select the one correct answer.
  HashMap
  TreeMap
  HashTable
  HashSet
132. Which of the following are true about interfaces. Select the correct answer.
  Methods declared in interfaces are implicitly private.
  Variables declared in interfaces are implicitly public, static, and final.
  The keyword implements indicate that an interface inherits from another.
  An interface can not extend any number of interfaces.
133. What is the return type of method round(double d) defined in Math class?
  int
  long
  float
  double
134. Which of the class defined in java.io and used for file-handling is abstract. Select the correct answer.
  PrintStream
  Reader
  FileInputStream
  FileWriter
135. Select the one correct answer. Which method defined in Integer class can be used to convert an Integer object to primitive int type.
  valueOf
  intValue
  getInt
  getInteger
136. Name the return type of method hashCode() defined in Object class, which is used to get the unique hash value of an Object.
  short
  int
  long
  double
137. Name the keyword that makes a variable belong to a class, rather than being defined for each instance of the class. Select the one correct answer.
  final
  static
  volatile
  native
138. Java support RMI. What does this RMI stands for?
  Redundant Memory Invocation
  Random Memory Invocation
  Remote Method Invocation
139. public class Wbfile
{
public static void main (String[] args)
{
String a = args[1];
String b = args[2];
String c = args[3];
System.out.println("Arg is " + c);
}
}
Select how you would start the program to cause it to print: Arg is 2
  java Wbfile 222
  java Wbfile 1 2 2 3 4
  java Wbfile 1 3 2 2
  java Wbfile 0 1 2 3
140. Which class does not override the equals() and hashCode() methods, inheriting them directly from class Object?
  java.lang.String
  java.lang.Double
  java.lang.StringBuffer
  java.lang.Character
141. You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability?
  Java.util.Collection
  Java.util.List
  Java.util.Map
  None of the above
142. What is the numerical range of char?
  -256 to 255
  0 to 32767
  0 to 65535
  -32768 to 32767
143. Which cannot directly cause a thread to stop executing?
  Calling the SetPriority() method on a Thread object.
  Calling the wait() method on an object.
  Calling notify() method on an object.
  Calling read() method on an InputStream object.
144. Which method must be defined by a class implementing the java.lang.Runnable interface?
  void run()
  public void start()
  public void run()
  void run(int priority)
145. Which is a reserved word in the Java programming language?
  subclasses
  reference
  native
  method
146. Which one is a valid declaration of a boolean?
  boolean b = 0;
  boolean b = 'false';
  boolean b = false;
  boolean b = Boolean.false();
147. In which case does the compiler supply a default constructor for class A?
  class A {
public A( ) {
}
}
  class A {
public A(int x) {
}
}
  class Z {
}
class A extends Z {
void A( ) {
}
}
148. Given: public class Test { }

What is the prototype of the default constructor?
  private Test( )
  Test(void)
  public Test( )
  public Test(void)
149. You want subclasses in any package to have access to members of a superclass. Which is the most restrictive access that accomplishes this objective?
  public
  private
  protected
  transient
150. Which one create an instance of an array?
  float fa = new float[20];
  char[ ] ca = "Some String";
  Object oa = new float[20];
©2024 WithoutBook